﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Windows.Media;

namespace FarpacHelper
{
    public struct Preset
    {
        public string Name { get; private set; }
        public string[] ToolString { get; private set; }
        public Preset(string name, string[] toolstring)
            : this()
        {
            Name = name;
            ToolString = toolstring;
        }
    }

    public class RunIH : INotifyPropertyChanged
    {
        public int ColumnXLS { get; set; }
        public int Number { get; set; }
        public string NamePreset { get; set; }
        public ObservableCollection<string> ToolString { get; set; }
        bool enabled;
        public bool Enabled
        {
            get { return enabled; }
            set
            {
                if (value != enabled)
                {
                    enabled = value;
                    OnPropertyChanged("Enabled");
                    Foreground = enabled ? Brushes.Black : Brushes.LightGray;
                }
            }
        }
        Brush foreground;
        public Brush Foreground
        {
            get { return foreground; }
            set { if (value != foreground) { foreground = value; OnPropertyChanged("Foreground"); } }
        }
        public RunIH(int number, string namePreset, IEnumerable<string> toolstring, int columnXLS = 0)
        {
            Number = number;
            NamePreset = namePreset;
            ToolString = new ObservableCollection<string>(); Foreground = Brushes.LightGray;
            ToolString.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ToolString_CollectionChanged);
            foreach (string s in toolstring) ToolString.Add(s);
            ColumnXLS = columnXLS;
        }

        void ToolString_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            Enabled = (ToolString.Count == 0) ? false : true;
            /*if ((sender as ObservableCollection<string>).Count == 0) Enabled = false;
            else Enabled = true;*/
        }

        #region INotifyPropertyChanged Members
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        // Create the OnPropertyChanged method to raise the event 
        protected void OnPropertyChanged(string name)
        {
            System.ComponentModel.PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new System.ComponentModel.PropertyChangedEventArgs(name));
            }
        }
        #endregion
    }
}
